package com.echo.sdk.im.model;

import com.alibaba.fastjson.JSON;
import io.netty.handler.codec.http.FullHttpRequest;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.HashMap;

/**
 * @Author chentl
 * @Version V1.0
 * @Project wh-bigdata-frame.
 * @Title CIMMsg
 * @Description 消息通信主题对象
 * @Package com.echo.sdk.im.server.model
 * @Date 2021/6/18 4:01 下午
 * @Copyright: 武汉大数据产业发展有限公司 All rights reserved.
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CIMMsg implements Serializable {

    private static final long serialVersionUID = 1L;

    //服务端推送给客户端构造
    public CIMMsg(String userId, String type, String theme, Object data) {
        this.userId = userId;
        this.type = type;
        this.theme = theme;
        this.data = data;
    }

    //文件上传构造
    public CIMMsg(FullHttpRequest request, String type) {
        this.request = request;
        this.type = type;
    }

    //服务端推送给客户端构造-主题广播
    public CIMMsg(String type, String theme, Object data) {
        this.type = type;
        this.theme = theme;
        this.data = data;
    }

    //服务端推送给客户端外部Teams消息构造
    public CIMMsg(String channelId, String userId, String account, String type, String theme, Object data) {
        this.channelId = channelId;
        this.userId = userId;
        this.account = account;
        this.type = type;
        this.theme = theme;
        this.data = data;
    }

    /**
     * 用户id
     */
    private String userId;
    /**
     * session绑定的账号名称
     */
    private String account;
    /**
     * 频道ID
     */
    private String channelId;
    /**
     * 消息类型
     */
    private String type;
    /**
     * 主题 | sendMsg
     */
    private String theme;
    /**
     * 消息对象
     */
    private Object data;
    /**
     * 时间戳
     */
    private long timestamp;
    /**
     * 连接id
     */
    private String nid;

    /**
     * 连接客户端信息
     */
    private HashMap<String, String> clientInfo = new HashMap<>();

    /**
     * Http请求
     */
    private FullHttpRequest request;

    /**
     * 用于推送刷 未读统计 消息
     *
     * @param type
     * @param data
     */
    public CIMMsg(String type, Object data) {
        this.type = type;
        this.data = data;
    }

    public CIMMsg(String type) {
        this.type = type;
    }

    public String get(String k) {
        return clientInfo.get(k);
    }

    public String getContent() {
        return JSON.toJSONString(data);
    }


    public String toJsonString() {
        return JSON.toJSONString(this);
    }
}
